//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __ELAPI_H__
#define __ELAPI_H__

#include <elastos.h>

// EXTERN_C DLLEXP const _ELASTOS ClassID ECLSID_CAppletHosting;

#ifdef _UNDEFDLLEXP
#include <elasys_server.h>
#else
#include <elasys.h>
#endif

#include <elconsole.h>

ELAPI _CSystem_RegisterRunningObject(
            _ELASTOS WString name,
            PInterface pService);

ELAPI _CSystem_FindRunningObject(
            _ELASTOS WString name,
            PInterface *pService);

ELAPI _CSystem_WaitForRunningObject(
            _ELASTOS WString name,
            _ELASTOS Int32 timeout,
            WaitResult *pResult);

ELAPI _CSystem_UnregisterRunningObject(
            _ELASTOS WString name);

ELAPI _CSystem_GetMachineTime(
            _ELASTOS SystemTime *pSystemTime);

ELAPI _CSystem_SetMachineTime(
            _ELASTOS SystemTime systemTime);

ELAPI_(_ELASTOS Microsecond32) _CSystem_GetElapsedTime();

ELAPI_(_ELASTOS Microsecond32) _CSystem_GetIdleTime();

ELAPI_(_ELASTOS Int32) _CSystem_GetVersion();

ELAPI _CSystem_GetGlobalMemorySizes(
            _ELASTOS Int32 *pTotalPhysicalMemorySize,
            _ELASTOS Int32 *pAvailablePhysicalMemorySize);

ELAPI _CSystem_DebugPrint(
            _ELASTOS WString string);

ELAPI _CProcess_NewUnstarted(
            IProcess **ppProcess);

ELAPI _CProcess_New(
            _ELASTOS WString name,
            _ELASTOS WString args,
            IProcess **ppProcess);

ELAPI _CSystem_GetAllProcesses(
            IObjectEnumerator **ppProcesses);

ELAPI_(IProcess *) _CProcess_GetCurrent();

ELAPI_(void) _CProcess_Terminate(
            ExitCode exitCode);

ELAPI_(void) _CProcess_Exit(
            ExitCode exitCode);

ELAPI _CProcess_AtExit(
            PProcessExitRoutine pEntry,
            _ELASTOS PVoid pUserData);

ELAPI _CModule_Load(
            _ELASTOS WString name,
            _ELASTOS ModuleLoadFlags flags,
            IModule **ppModule);

ELAPI _CProcess_FreeUnusedModule(_ELASTOS WString wszDllName);

ELAPI_(void) _CProcess_FreeUnusedModules(_ELASTOS Boolean bImmediate);

ELAPI _CModule_GetCurrent(
            IModule **ppIModule);

ELAPI _CThread_New(
            PThreadMain pEntry,
            _ELASTOS PVoid pArg,
            _ELASTOS ThreadCreationFlags flags,
            IThread **ppThread);

ELAPI _CThread_AtQuit(
            PThreadQuitRoutine pEntry,
            _ELASTOS PVoid pUserData);

ELAPI_(IThread *) _CThread_GetCurrent();

ELAPI_(void) _CThread_Quit(
            ExitCode exitCode);

ELAPI_(void) _Impl_CallbackSink_FreeCallbackEvent(
            _ELASTOS PVoid pCallbackEvent);

typedef _ELASTOS Int32 CallbackEventId;
typedef _ELASTOS Int32 CallbackEventFlags;

#define CallbackEventFlag_PriorityMask  0x000000FF
#define CallbackEventFlag_Normal        0x00000000
#define CallbackEventFlag_Duplicated    0x00000100
#define CallbackEventFlag_SyncCall      0x00000200
#define CallbackEventFlag_DirectCall    0x00000400

#define CallingStatus_Created       0x01
#define CallingStatus_Running       0x02
#define CallingStatus_Completed     0x03
#define CallingStatus_Cancelled     0x04

typedef _ELASTOS ECode (ELFUNCCALLTYPE *PCallbackEventHandleRoutine)(_ELASTOS PVoid pvThis);

typedef _ELASTOS ECode (ELFUNCCALLTYPE *PCoalesceEventFunc)(_ELASTOS PVoid* ppOld, _ELASTOS PVoid* ppNew);

#define THREAD_STACK_LIMIT  (0x80000000 - 0x400000)
#ifdef _neptune
#define THREAD_STACK_BASE   0x77D00000
#else
#define THREAD_STACK_BASE   0x60000000
#endif

#ifdef __cplusplus

#include <linknode.h>

class _CMapNode : public DLinkNode
{
public:
    _ELASTOS WChar*  m_pwcsKey;
    _ELASTOS WChar*  m_pwcsValue;
};

ELAPI_(_CMapNode*) _Impl_CMap_AllocNode(_ELASTOS WString key, _ELASTOS WString value);

ELAPI_(void) _Impl_CMap_FreeNode(_CMapNode* node);

class _EzCallbackEvent : public DLinkNode
{
public:
    _EzCallbackEvent(
        CallbackEventId id,
        CallbackEventFlags flags,
        PInterface pSender,
        PInterface pReceiver,
        _ELASTOS PVoid pDomain,
        PCallbackEventHandleRoutine pHandleRoutine,
        PCoalesceEventFunc pCoalesceFunc,
        _ELASTOS PVoid pHandlerThis,
        _ELASTOS PVoid pHandlerFunc,
        _ELASTOS Int32 typeOfFunc) : m_id(id), m_flags(flags),
            m_pSender(pSender), m_pReceiver(pReceiver), m_pDomain(pDomain),
            m_pHandleRoutine(pHandleRoutine), m_pCoalesceFunc(pCoalesceFunc),
            m_pHandlerThis(pHandlerThis), m_pHandlerFunc(pHandlerFunc),
            m_typeOfFunc(typeOfFunc), m_ecRet(NOERROR), m_pSyncEvent(NULL),
            m_Status(CallingStatus_Created), m_bCompleted(0)
    {
        if (m_pSender) m_pSender->AddRef();
        AddRef();
    }

    virtual ~_EzCallbackEvent()
    {
        if (m_pSender) m_pSender->Release();
        if (m_pSyncEvent) {
            m_pSyncEvent->Notify(2);
            m_pSyncEvent->Release();
        }
    }

    _ELASTOS UInt32 AddRef() { return m_cRef.Increment(); }

    _ELASTOS UInt32 Release()
    {
        _ELASTOS Int32 nRef = m_cRef.Decrement();
        if (nRef == 0) _Impl_CallbackSink_FreeCallbackEvent(this);
        return nRef;
    }

public:
    CallbackEventId             m_id;
    CallbackEventFlags          m_flags;
    PInterface                  m_pSender;
    PInterface                  m_pReceiver;
    _ELASTOS PVoid              m_pDomain;
    PCallbackEventHandleRoutine m_pHandleRoutine;
    PCoalesceEventFunc          m_pCoalesceFunc;
    _ELASTOS PVoid              m_pHandlerThis;
    _ELASTOS PVoid              m_pHandlerFunc;
    _ELASTOS Int32              m_typeOfFunc;
    _ELASTOS ECode              m_ecRet;
    IEvent*                     m_pSyncEvent;
    _ELASTOS Int16              m_Status;
    _ELASTOS Int16              m_bCompleted;
private:
    Interlocked                 m_cRef;
};

typedef class _EzCallbackEvent  *PCallbackEvent;

class StaticObject : public SingleLinkNode
{
public:
    StaticObject(PInterface pObj):m_pObject(pObj) { }
    ~StaticObject()
    {
        if (m_pObject) m_pObject->Release();
    }

    PInterface m_pObject;
};

typedef class StaticObject *PStaticObject;

#else

typedef _ELASTOS PVoid PCallbackEvent;

#endif // __cplusplus

ELAPI _Impl_CallbackSink_InitCallbackContext(
            PInterface *ppCallbackContext);

ELAPI _Impl_CallbackSink_GetCallbackContext(
            PInterface *ppCallbackContext);

ELAPI _Impl_CallbackSink_SetDefaultCallbackContext(
            PInterface pCallbackContext);

ELAPI _Impl_CallbackSink_GetDefaultCallbackContext(
            PInterface *ppCallbackContext);

ELAPI _Impl_CallbackSink_AcquireCallbackContext(
            PInterface *ppCallbackContext);

ELAPI_(PCallbackEvent) _Impl_CallbackSink_AllocCallbackEvent(
            _ELASTOS MemorySize size);


ELAPI _Impl_CallbackSink_GetThreadEvent(
            PInterface pCallbackContext, IEvent** ppEvent);

ELAPI _Impl_CallbackSink_PostCallbackEvent(
            PInterface pCallbackContext,
            PCallbackEvent pCallbackEvent);

ELAPI _Impl_CallbackSink_SendCallbackEvent(
            PInterface pCallbackContext,
            PCallbackEvent pCallbackEvent,
            _ELASTOS Millisecond32 timeOut);

ELAPI _Impl_CallbackSink_WaitForCallbackEvent(
            PInterface pCallbackContext,
            _ELASTOS Millisecond32 msTimeOut,
            WaitResult* pResult,
            _ELASTOS Boolean *pbEventOccured,
            _ELASTOS Flags32 fPriority);

ELAPI _Impl_CallbackSink_CleanupAllCallbacks(
    IInterface *pCallbackContext);

ELAPI _Impl_CallbackSink_CancelPendingAllCallbacks(
            PInterface pCallbackContext,
            PInterface pSender);

ELAPI _Impl_CallbackSink_CancelPendingCallback(
            PInterface pCallbackContext,
            PInterface pSender,
            CallbackEventId id);

ELAPI _Impl_CallbackSink_CancelCallbackEvents(
            PInterface pCallbackContext,
            PInterface pSender,
            CallbackEventId id,
            _ELASTOS PVoid pHandlerThis,
            _ELASTOS PVoid pHandlerFunc);

ELAPI _Impl_CallbackSink_RequestToFinish(
    PInterface pCallbackContext, AppletFinish Flag);

ELAPI_(AppletStatus) _Impl_CallbackSink_GetStatus(
    PInterface pCallbackContext);

ELAPI_(ExitCode) _Impl_CallbackSink_TryToHandleEvents();

ELAPI _Impl_CCallbackRendezvous_New(
        PInterface pCallbackContext,
        ICallbackSink* pCallbackSink,
        CallbackEventId eventId,
        _ELASTOS Boolean* pbEventFlag,
        _ELASTOS Boolean bNewCallback,
        ICallbackRendezvous** ppICallbackRendezvous);

ELAPI _CThread_Sleep(
            _ELASTOS Millisecond32 ms,
            WaitResult *pResult);

ELAPI _CThread_Delay(
            _ELASTOS Microsecond32 us);

ELAPI _CThread_Yield();

ELAPI _CVirtualMemory_Alloc(
            _ELASTOS Address baseAddr,
            _ELASTOS MemorySize size,
            _ELASTOS MemoryMapFlags flags,
            MemoryProtection protect,
            _ELASTOS Address *pBaseAddr);

ELAPI _CVirtualMemory_Query(
            _ELASTOS Address vAddress,
            _ELASTOS Address *pBaseAddr,
            _ELASTOS MemorySize *pSize);

ELAPI _CVirtualMemory_QueryPhysicalBlock(
            _ELASTOS Address vAddress,
            _ELASTOS Address *pAddress,
            _ELASTOS MemorySize *pSize);

ELAPI _CVirtualMemory_SetProtection(
            _ELASTOS Address baseAddr,
            _ELASTOS MemorySize size,
            MemoryProtection protect);

ELAPI _CVirtualMemory_CheckProtection(
            _ELASTOS Address address,
            MemoryProtection protect,
            _ELASTOS Boolean *pIsValid);

ELAPI _CVirtualMemory_Commit(
            _ELASTOS Address address);

ELAPI _CVirtualMemory_Free(
            _ELASTOS Address baseAddr,
            _ELASTOS MemorySize size);

ELAPI _CVirtualMemory_IoRemap(
            _ELASTOS Address virtualAddr,
            _ELASTOS MemorySize size,
            _ELASTOS Address physicalAddr,
            _ELASTOS MemoryMapFlags flags,
            MemoryProtection protect,
            _ELASTOS Address *pVirtualAddr);

ELAPI _CMutex_New(
        /* [out] */ IMutex **ppMutex);

ELAPI _CCondition_New(
        /* [out] */ ICondition **ppCondition);

ELAPI _CEvent_New(
        /* [in] */ _ELASTOS Boolean manualReset,
        /* [in] */ _ELASTOS EventState initialState,
        /* [out] */ IEvent **ppEvent);

ELAPI _CReaderWriterLock_New(
        /* [out] */ IReaderWriterLock **ppRWLock);

ELAPI _CMutex_NewWithName(
        /* [in] */ _ELASTOS WString name,
        /* [out] */ IMutex **ppMutex,
        /* [out] */ _ELASTOS Boolean *pAlreadyExists);

ELAPI _CCondition_NewWithName(
        /* [in] */ _ELASTOS WString name,
        /* [out] */ ICondition **ppCondition,
        /* [out] */ _ELASTOS Boolean *pAlreadyExists);

ELAPI _CEvent_NewWithName(
        /* [in] */ _ELASTOS WString name,
        /* [in] */ _ELASTOS Boolean manualReset,
        /* [in] */ _ELASTOS EventState initialState,
        /* [out] */ IEvent **ppEvent,
        /* [out] */ _ELASTOS Boolean *pAlreadyExists);

ELAPI _CReaderWriterLock_NewWithName(
        /* [in] */ _ELASTOS WString name,
        /* [out] */ IReaderWriterLock **ppRWLock,
        /* [out] */ _ELASTOS Boolean *pAlreadyExists);

ELAPI _CSharedMemory_New(
        /* [in] */ _ELASTOS WString name,
        /* [in] */ _ELASTOS MemorySize size,
        /* [in] */ _ELASTOS Boolean reserved,
        /* [out] */ ISharedMemory **ppSharedMemory,
        /* [out] */ _ELASTOS Boolean *pAlreadyExists);

ELAPI _CSystem_CreateSystemEventHandle(
        /* [in] */ _ELASTOS SystemEvents interestedEvents,
        /* [out] */ IEvent **ppEvent);

ELAPI _CSystem_WaitForAnySystemEvent(
        /* [in] */ _ELASTOS SystemEvents interestedEvents,
        /* [out] */ SystemEvent *pSystemEvent);

ELAPI _CHostingManager_Acquire(
        /* [out] */ IHostingManager **ppManager);

ELAPI _CCriticalSection_Initialize(
        /* [in] */ _ELASTOS CriticalSection *pCriticalSection);

ELAPI_(void) _CCriticalSection_Enter(
        /* [in] */ _ELASTOS CriticalSection *pCriticalSection);

ELAPI _CCriticalSection_TryEnter(
       /* [in] */ _ELASTOS CriticalSection *pCriticalSection,
       /* [out] */ _ELASTOS Boolean *pEntered);

ELAPI_(void) _CCriticalSection_Leave(
        /* [in] */ _ELASTOS CriticalSection *pCriticalSection);

ELAPI_(void) _CCriticalSection_Terminate(
        /* [in] */ _ELASTOS CriticalSection *pCriticalSection);

ELAPI _CThread_AcquireLocalSlot(
        /* [in] */ ThreadLocalSlotType slotType,
        /* [out] */ _ELASTOS Int32 *pSlotIndex);

ELAPI _CThread_RelinquishLocalSlot(
        /* [in] */ _ELASTOS Address slotIndex);

ELAPI _CThread_SetLocalValue(
        /* [in] */ _ELASTOS Int32 slotIndex,
        /* [in] */ _ELASTOS TLValue value);

ELAPI _CThread_SetLocalMemory(
        /* [in] */ _ELASTOS Int32 slotIndex,
        /* [in] */ _ELASTOS PVoid pMem);

ELAPI _CThread_SetLocalObject(
        /* [in] */ _ELASTOS Int32 slotIndex,
        /* [in] */ PInterface pObj);

ELAPI _CThread_GetLocalValue(
        /* [in] */ _ELASTOS Int32 slotIndex,
        /* [out] */ _ELASTOS TLValue *pValue);

ELAPI _CThread_GetLocalMemory(
        /* [in] */ _ELASTOS Int32 slotIndex,
        /* [out] */ _ELASTOS PVoid *ppMem);

ELAPI _CThread_GetLocalObject(
        /* [in] */ _ELASTOS Int32 slotIndex,
        /* [out] */ PInterface *ppObj);

ELAPI EzSetModuleGlobalValue(
        /* [in] */ _ELASTOS PVoid value);

ELAPI EzSetModuleGlobalMem(
        /* [in] */ _ELASTOS PVoid pMem);

ELAPI EzSetModuleGlobalObj(
        /* [in] */ PInterface pObj);

ELAPI EzGetModuleGlobalValue(
        /* [out] */ _ELASTOS PVoid *pValue);

ELAPI EzGetModuleGlobalMem(
        /* [out] */ _ELASTOS PVoid *ppMem);

ELAPI EzGetModuleGlobalObj(
        /* [out] */ PInterface *ppObj);

ELAPI _CProcess_FlushInstructionCache(
        /* [in] */ _ELASTOS Address baseAddr,
        /* [in] */ _ELASTOS MemorySize size);

#ifdef __cplusplus

ELAPI _CEvent_WaitForAnyEvents(
        /* [in] */ const _ELASTOS BufferOf<IEvent *> * events,
        /* [out] */ WaitResult *pResult,
        /* [out] */ _ELASTOS Int32 *pIndex,
        /* [out] */ _ELASTOS EventState *pState);

ELAPI _CEvent_TryWaitForAnyEvents(
        /* [in] */ const _ELASTOS BufferOf<IEvent *> * events,
        /* [in] */ _ELASTOS Millisecond32 timeout,
        /* [out] */ WaitResult *pResult,
        /* [out] */ _ELASTOS Int32 *pIndex,
        /* [out] */ _ELASTOS EventState *pState);

#else // !__cplusplus

ELAPI _CEvent_WaitForAnyEvents(
        /* [in] */ const _ELASTOS PCarQuintet events,
        /* [out] */ WaitResult *pResult,
        /* [out] */ _ELASTOS Int32 *pIndex,
        /* [out] */ _ELASTOS EventState *pState);

ELAPI _CEvent_TryWaitForAnyEvents(
        /* [in] */ const _ELASTOS PCarQuintet events,
        /* [in] */ _ELASTOS Millisecond32 timeout,
        /* [out] */ WaitResult *pResult,
        /* [out] */ _ELASTOS Int32 *pIndex,
        /* [out] */ _ELASTOS EventState *pState);
#endif

ELAPI _CSystem_Reboot();

ELAPI _CSystem_QueryPerformanceCounter(
        /* [out] */ _ELASTOS Int64 *pPerformanceCount);

ELAPI _CSystem_QueryPerformanceFrequency(
        /* [out] */ _ELASTOS Int64 *pFrequency);

struct KBDStatus;

ELAPI _EzGetVirKey(
        /* [out] */ struct KBDStatus *pVirutalCode);

ELAPI_(int) _Impl_VcodeToAscii(
        /* [in] */ uint8_t uVirtualcode,
        /* [in] */ uint16_t uLedState,
        /* [in] */ uint16_t uKeyboardState);

ELAPI _Impl_GetChar(_ELASTOS UInt32 toRead, _ELASTOS MemoryBuf * pBuf,
    _ELASTOS Boolean bBuffer);

ELAPI _Impl_GetStartInfo(
        /* [out] */ _ELASTOS WStringBuf * pCmdName,
        /* [out] */ _ELASTOS WStringBuf * pCmdArgs);

ELAPI _CProfile_GetAString(
        /* [in] */ _ELASTOS AString appName,
        /* [in] */ _ELASTOS AString keyName,
        /* [out] */ _ELASTOS AStringBuf *pReturnedString);

ELAPI _CProfile_GetWString(
        /* [in] */ _ELASTOS WString appName,
        /* [in] */ _ELASTOS WString keyName,
        /* [out] */ _ELASTOS WStringBuf *pReturnedString);

ELAPI _CProfile_GetInt32(
        /* [in] */ _ELASTOS AString appName,
        /* [in] */ _ELASTOS AString keyName,
        /* [out] */ _ELASTOS Int32 * pValue);

ELAPI _CPrivateProfile_GetAString(
        /* [in] */ _ELASTOS AString fileName,
        /* [in] */ _ELASTOS AString appName,
        /* [in] */ _ELASTOS AString keyName,
        /* [out] */ _ELASTOS AStringBuf *pReturnedString);

ELAPI _CPrivateProfile_GetWString(
        /* [in] */ _ELASTOS WString fileName,
        /* [in] */ _ELASTOS WString appName,
        /* [in] */ _ELASTOS WString keyName,
        /* [out] */ _ELASTOS WStringBuf *pReturnedString);

ELAPI _CPrivateProfile_GetInt32(
        /* [in] */ _ELASTOS AString fileName,
        /* [in] */ _ELASTOS AString appName,
        /* [in] */ _ELASTOS AString keyName,
        /* [out] */ _ELASTOS Int32 * pValue);

ELAPI _CPrivateProfile_SetAString(
        /* [in] */ _ELASTOS AString fileName,
        /* [in] */ _ELASTOS AString appName,
        /* [in] */ _ELASTOS AString keyName,
        /* [in] */ _ELASTOS AString value);

ELAPI _CPrivateProfile_SetWString(
    /* [in] */ _ELASTOS WString fileName,
    /* [in] */ _ELASTOS WString appName,
    /* [in] */ _ELASTOS WString keyName,
    /* [in] */ _ELASTOS WString value);

ELAPI _EzSetStdDevice(
        /* [in] */ _ELASTOS UInt32 stdDeviceNo,
        /* [in] */ _ELASTOS WString fileName);

ELAPI _EzGetStdDevice(
        /* [in] */ _ELASTOS UInt32 stdDeviceNo,
        /* [Out]*/ _ELASTOS WChar ** ppFileName);

ELAPI EzNotify(
        /* [in] */ int eType,
        /* [in] */ int nCode,
        /* [in] */ void *pParam);

ELAPI _CErrorReport_SetWString(
        /* [in] */ _ELASTOS WString string);

ELAPI _CErrorReport_SetAString(
        /* [in] */ _ELASTOS AString string);

ELAPI _CErrorReport_SetUrl(
        /* [in] */ _ELASTOS AString url);

#ifdef _MSVC
#pragma warning( disable : 4190 )
#endif

ELAPI_(_ELASTOS WString) _CErrorReport_GetWString();

ELAPI_(_ELASTOS AString) _CErrorReport_GetAString();

ELAPI_(_ELASTOS AString) _CErrorReport_GetUrl();

#ifdef _MSVC
#pragma warning( default : 4190 )
#endif

ELAPI_(_ELASTOS PVoid) GetErrorInfo();

ELAPI _CReflector_AcquireModuleInfo(
    /* [in] */ _ELASTOS WString wsName,
    /* [out] */ IModuleInfo **piModuleInfo);

ELAPI _CReflector_AcquireIntrinsicTypeInfo(
    /* [in] */ CarDataType intrinsicType,
    /* [out] */ IDataTypeInfo **ppIntrinsicTypeInfo);

#ifdef __cplusplus
ELAPI _CReflector_AcquireEnumInfo(
    /* [in] */ _ELASTOS AString name,
    /* [in] */ const _ELASTOS BufferOf<_ELASTOS AString> *pItemNames,
    /* [in] */ const _ELASTOS BufferOf<_ELASTOS Int32> *pItemValues,
    /* [out] */ IEnumInfo **ppEnumInfo);


ELAPI _CReflector_AcquireStructInfo(
    /* [in] */ _ELASTOS AString name,
    /* [in] */ const _ELASTOS BufferOf<_ELASTOS AString> *pFieldNames,
    /* [in] */ const _ELASTOS BufferOf<IDataTypeInfo *> *pFieldTypeInfos,
    /* [out] */ IStructInfo **ppStructInfo);
#else

ELAPI _CReflector_AcquireEnumInfo(
    /* [in] */ _ELASTOS AString name,
    /* [in] */ const _ELASTOS PCarQuintet pItemNames,
    /* [in] */ const _ELASTOS PCarQuintet pItemValues,
    /* [out] */ IEnumInfo **ppEnumInfo);


ELAPI _CReflector_AcquireStructInfo(
    /* [in] */ _ELASTOS AString name,
    /* [in] */ const _ELASTOS PCarQuintet pFieldNames,
    /* [in] */ const _ELASTOS PCarQuintet pFieldTypeInfos,
    /* [out] */ IStructInfo **ppStructInfo);
#endif

ELAPI _CReflector_AcquireCppVectorInfo(
    /* [in] */ IDataTypeInfo *pElementTypeInfo,
    /* [in] */ _ELASTOS Int32 length,
    /* [out] */ ICppVectorInfo **ppCppVectorInfo);


ELAPI _CReflector_AcquireCarArrayInfo(
    /* [in] */ CarDataType quintetType,
    /* [in] */ IDataTypeInfo *pElementTypeInfo,
    /* [out] */ ICarArrayInfo **ppCarArrayInfo);

ELAPI _CObject_ReflectModuleInfo(
    /* [in] */ PInterface pObj,
    /* [out] */ IModuleInfo **piModuleInfo);

ELAPI _CObject_ReflectClassInfo(
    /* [in] */ PInterface pObj,
    /* [out] */ IClassInfo **piClassInfo);

ELAPI _CObject_ReflectInterfaceInfo(
    /* [in] */ PInterface pObj,
    /* [out] */ IInterfaceInfo **piInterfaceInfo);

ELAPI _ReleaseAtProcessExit(PInterface pObject);

ELAPI_(_ELASTOS Boolean) _Impl_CheckHelperInfoFlag(_ELASTOS Flags32 flag);

ELAPI_(void) _Impl_SetHelperInfoFlag(_ELASTOS Flags32 flag, _ELASTOS Boolean bValue);

ELAPI _Impl_EnterProtectedZone();

ELAPI _Impl_LeaveProtectedZone();

ELAPI _Impl_InsideProtectedZone();

ELAPI _CActiveTimer_New(
    /* [in] */ _ELASTOS Millisecond32 interval,
    /* [in] */ _ELASTOS ECode (ELAPICALLTYPE *pEntry)(_ELASTOS PVoid, IActiveTimer *),
    /* [in] */ _ELASTOS PVoid pUserData,
    /* [out] */ IActiveTimer ** ppActiveTimer);

ELAPI _Impl_CAppletContext_GetCurrent(PInterface* ppAppletContext);

ELAPI _Impl_CAppletContext_Initialize(IApplet* pApplet);

ELAPI _Impl_CAppletContext_Uninitialize();

ELAPI _CApplet_GetCurrent(PInterface* ppApplet);

ELAPI _CApplet_AtFinish(
            PThreadQuitRoutine pEntry,
            _ELASTOS PVoid pUserData);

ELAPI _CApplet_GetAllThreads(IObjectEnumerator** ppThreads);

ELAPI _Impl_TApplet_Create(
        _ELASTOS PVoid * ppAppletObj,
        PInterface * ppCallbackContext);

ELAPI _Impl_TApplet_Prepare(_ELASTOS PVoid pAppletObj);

ELAPI _Impl_TApplet_SetAppletPath(
        _ELASTOS PVoid pAppletObj,
        _ELASTOS WStringBuf* pAppletPath);

ELAPI _Impl_TApplet_DoWork(_ELASTOS PVoid pAppletObj, _ELASTOS ECode ec);


EXTERN_C int    __cdecl _Impl_Memcmp(const void *, const void *, size_t);
EXTERN_C void * __cdecl _Impl_Memset(void *, int, size_t);
EXTERN_C int    __cdecl _Impl_Wcscmp(const wchar_t* , const wchar_t* );


// callback helper api for making parameters

#define _Impl_GetUnknownCBEParamExtraSize(typeSize, param)        0
#define _Impl_GetIntrinsicCBEParamExtraSize(typeSize, param)      0
#define _Impl_GetEMuidCBEParamExtraSize(typeSize, param)          ROUNDUP2(typeSize, 4)
#define _Impl_GetEGuidCBEParamExtraSize(typeSize, param)          ROUNDUP2(typeSize, 4)

#define _Impl_GetInterfaceCBEParamExtraSize(typeSize, param)      0
#define _Impl_GetStructCBEParamExtraSize(typeSize, param)         ROUNDUP2(typeSize, 4)

#define _Impl_MakeUnknownCBEventParam(extraSize, ppBuf, pParam)   do {} while(0)
#define _Impl_MakeIntrinsicCBEventParam(extraSize, ppBuf, pParam) do {} while(0)
#define _Impl_MakeInterfaceCBEventParam(extraSize, ppBuf, pParam) do {} while(0)
#define _Impl_MakeStructCBEventParam(extraSize, ppBuf, ppParam) \
    do { \
        memcpy(*ppBuf, *ppParam, extraSize); \
        _ELASTOS PVoid *ppvParam = (_ELASTOS PVoid *)ppParam; \
        (*ppvParam) = (_ELASTOS PVoid)(*ppBuf); \
        (*ppBuf) += ROUNDUP2(extraSize, 4); \
    } while (0)

ELAPI_(_ELASTOS MemorySize) _Impl_GetCarArrayCBEParamExtraSize(
        _ELASTOS MemorySize typeSize, _ELASTOS PCarQuintet param);
ELAPI_(_ELASTOS MemorySize) _Impl_GetAStringCBEParamExtraSize(
        _ELASTOS MemorySize typeSize, _ELASTOS AString param);
ELAPI_(_ELASTOS MemorySize) _Impl_GetWStringCBEParamExtraSize(
        _ELASTOS MemorySize typeSize, _ELASTOS WString param);

#ifdef __cplusplus
ELAPI_(_ELASTOS MemorySize) _Impl_GetArrayOfAStringCBEParamExtraSize(
        _ELASTOS MemorySize typeSize, _ELASTOS ArrayOf<_ELASTOS AString> & param);
ELAPI_(_ELASTOS MemorySize) _Impl_GetArrayOfWStringCBEParamExtraSize(
        _ELASTOS MemorySize typeSize, _ELASTOS ArrayOf<_ELASTOS WString> & param);
ELAPI_(_ELASTOS MemorySize) _Impl_GetBufferOfAStringCBEParamExtraSize(
        _ELASTOS MemorySize typeSize, _ELASTOS BufferOf<_ELASTOS AString> & param);
ELAPI_(_ELASTOS MemorySize) _Impl_GetBufferOfWStringCBEParamExtraSize(
        _ELASTOS MemorySize typeSize, _ELASTOS BufferOf<_ELASTOS WString> & param);
#endif // __cplusplus

ELAPI_(void) _Impl_MakeEMuidCBEventParam(
    _ELASTOS MemorySize extraSize, _ELASTOS Byte **ppBuf, _ELASTOS PVoid *ppParam);
ELAPI_(void) _Impl_MakeEGuidCBEventParam(
    _ELASTOS MemorySize extraSize, _ELASTOS Byte **ppBuf, _ELASTOS PVoid *ppParam);
ELAPI_(void) _Impl_MakeCarArrayCBEventParam(
    _ELASTOS MemorySize extraSize, _ELASTOS Byte **ppBuf, _ELASTOS PVoid *ppParam);
ELAPI_(void) _Impl_MakeArrayOfAStringCBEventParam(
    _ELASTOS MemorySize extraSize, _ELASTOS Byte **ppBuf, _ELASTOS PVoid *ppParam);
ELAPI_(void) _Impl_MakeArrayOfWStringCBEventParam(
    _ELASTOS MemorySize extraSize, _ELASTOS Byte **ppBuf, _ELASTOS PVoid *ppParam);
ELAPI_(void) _Impl_MakeBufferOfAStringCBEventParam(
    _ELASTOS MemorySize extraSize, _ELASTOS Byte **ppBuf, _ELASTOS PVoid *ppParam);
ELAPI_(void) _Impl_MakeBufferOfWStringCBEventParam(
    _ELASTOS MemorySize extraSize, _ELASTOS Byte **ppBuf, _ELASTOS PVoid *ppParam);
ELAPI_(void) _Impl_MakeAStringCBEventParam(
    _ELASTOS MemorySize extraSize, _ELASTOS Byte **ppBuf, _ELASTOS PVoid *ppParam);
ELAPI_(void) _Impl_MakeWStringCBEventParam(
    _ELASTOS MemorySize extraSize, _ELASTOS Byte **ppBuf, _ELASTOS PVoid *ppParam);

ELAPI _Impl_CheckClsId(
    PInterface pServerObj,
    const _ELASTOS ClassID* pClassID,
    PInterface *ppServerObj);

ELAPI _Impl_AcquireCallbackHandler(
        PInterface pServerObj,
        _ELASTOS REIID iid,
        PInterface *ppHandler);

#endif // __ELAPI_H__
